package com.sinog.biz.service.xml.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.sinog.biz.config.ProvinceCodes3Config;
import com.sinog.biz.mapper.havexml.AbPrisonerMapper;
import com.sinog.biz.mapper.havexml.HnInterfaceOppositeMapper;
import com.sinog.biz.mapper.havexml.PrisonerFxMapper;
import com.sinog.biz.mapper.havexml.PrisonerMainMapper;
import com.sinog.biz.mapper.havexml.PrisonerXjxxMapper;
import com.sinog.biz.mapper.havexml.UploadAppendixFileMapper;
import com.sinog.biz.mapper.havexml.XjReceiptDataVoMapper;
import com.sinog.biz.mapper.havexml.XjReceiptMapper;
import com.sinog.biz.mapper.havexml.XxblMapper;
import com.sinog.biz.mapper.havexml.other.UserLoginDetailsMapper;
import com.sinog.biz.service.api.DataTransmissionService;
import com.sinog.biz.service.business.XxblService;
import com.sinog.biz.service.business.impl.PrisonerXjxxServiceImpl;
import com.sinog.biz.service.xml.InterfaceXjService;
import com.sinog.biz.util.CheckUtil;
import com.sinog.core.domain.PrisonerCjpg;
import com.sinog.core.domain.PrisonerFx;
import com.sinog.core.domain.PrisonerJxjs;
import com.sinog.core.domain.PrisonerMain;
import com.sinog.core.domain.PrisonerXjxx;
import com.sinog.core.domain.UserInterFaceEntity;
import com.sinog.core.domain.XjReceipt;
import com.sinog.core.domain.XjReceiptData;
import com.sinog.core.domain.xml.HnInterfaceOpposite;
import com.sinog.core.domain.xml.HnInterfaceOppositeLog;
import com.sinog.core.model.PrisonerXixxVo;
import com.sinog.core.model.UploadAppendixFile;
import com.sinog.core.model.XjReceiptDataVo;
import com.sinog.core.model.xml.HnMessageVo;
import com.sinog.core.util.DateUtil;
import com.sinog.core.util.JsonUtil;
import com.sinog.core.util.MapUtil;
import com.sinog.core.utilbean.Constants;
import com.sinog.core.utilbean.HnStyleReturnCode;
import com.sinog.core.utilbean.IdGen;
import com.sinog.core.utilbean.Result;
import com.sinog.core.utilbean.ReturnCode;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @desc 湖南个性化对接 - 信息补录-衔接
 * @author lk
 * @date 2022/6/27 下午3:04
 */
@Slf4j
@Service
public class InterfaceXjServiceImpl implements InterfaceXjService {
    @Resource
    private XxblMapper xxblMapper;
    @Resource
    private PrisonerFxMapper prisonerFxMapper;
    @Resource
    private PrisonerMainMapper prisonerMainMapper;
    @Resource
    private XjReceiptMapper xjReceiptMapper;
    @Autowired
    private PrisonerXjxxServiceImpl prisonerXjxxService;
    @Resource
    private CheckUtil checkUtil;
    @Resource
    private XxblService xxblService;
    @Resource
    private UserLoginDetailsMapper userLoginDetailsMapper;
    @Resource
    private HnInterfaceOppositeMapper hnInterfaceOppositeMapper;
    @Resource
    private XjReceiptDataVoMapper xjReceiptDataVoMapper;
    @Resource
    private AbPrisonerMapper abPrisonerMapper;
    @Resource
    private DataTransmissionService dataTransmissionService;
    @Resource
    private PrisonerXjxxMapper prisonerXjxxMapper;
    @Resource
    private UploadAppendixFileMapper uploadAppendixFileMapper;
    @Resource
    private ProvinceCodes3Config provinceCodes3Config;

    /**
     * 信息补录接口
     * @param data 减刑假释-出监评估
     * @return Result
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result saveInformationBl(Map<String,List<Map<String,String>>> data) throws Exception {
        //封装转换参数
        String processType = data.get("processType").get(0).get("processType");
        HnMessageVo hnMessage = JsonUtil.toBean(JsonUtil.toText(data.get("MESSAGE").get(0)),HnMessageVo.class);
        // 出监狱评估信息校验
        Result resultCheck = checkUtil.checkParams(data);
        if(!ReturnCode.SUCCESS.code().equals(resultCheck.getCode())) {
            return Result.failure(resultCheck.getCode(),(String)resultCheck.getData(),getResultMapC(hnMessage,Constants.NumberStr.NUM_STR_TWO));
        }
        Result result;
        try {
            result = checkUtil.asscessParams(data,processType);
        } catch(Exception e) {
            throw new RuntimeException(e);
        }
        Map<String,Object> map = (Map<String,Object>)result.getData();
        //流程节点记录信息
        PrisonerJxjs[] jxjs = (PrisonerJxjs[])map.get("jxjs");
        Date date1 = new Date();
        PrisonerFx cjpgFx = (PrisonerFx)map.get("cjpgFx");
        PrisonerCjpg cjpg = (PrisonerCjpg)map.get("cjpg");
        hnMessage = (HnMessageVo)map.get("hnMessage");
        String kbmrybh = cjpg.getKbmrybh();
        //信息补录
        HnInterfaceOpposite hnInterfaceOpposite = hnInterfaceOppositeMapper.selectHnByKbmrybh(kbmrybh,Constants.HnInterfaceDocking.ZERO_SEVEN_ZERO_TWO_A,Constants.NumberStr.NUM_STR_ZERO);
        if(null != hnInterfaceOpposite) {
            String priNum = hnInterfaceOpposite.getPriNum();
            PrisonerMain prisonerInfoByPrinum = prisonerMainMapper.selectPrisonerMain(priNum);
            if(ObjectUtils.isEmpty(prisonerInfoByPrinum) || !prisonerInfoByPrinum.getState().equals(Constants.NumberStr.NUM_STR_THREE)) {
                return Result.failure(HnStyleReturnCode.ZFBH_XXBU_HCSTATE_IS_NOT,getResultMapC(hnMessage,Constants.NumberStr.NUM_STR_TWO));
            }
            // 获取接口对接用户
            String fsdwCode = hnMessage.getFsdwCode();
            UserInterFaceEntity user = userLoginDetailsMapper.getInfoByDepartId(fsdwCode);
            if(null == user) {
                // 找不到用户
                return Result.failure(HnStyleReturnCode.NOT_FIND_USER,getResultMapC(hnMessage,Constants.NumberStr.NUM_STR_TWO));
            }
            // 判断是否存在上一个0702C节点,如果存在则将节点记录废
            HnInterfaceOpposite hnInterfaceOppositeSecond = hnInterfaceOppositeMapper.selectHnByKbmrybh(kbmrybh,Constants.HnInterfaceDocking.ZERO_SEVEN_ZERO_TWO_C,Constants.NumberStr.NUM_STR_ZERO);
            if(null != hnInterfaceOppositeSecond){
                //查询该人员是否已经转入安置
                Map<String,Object> abPrisonersResultVo = abPrisonerMapper.getBaseInfoByPriNum(priNum);
                if(MapUtils.isNotEmpty(abPrisonersResultVo)){
                    return Result.failure(HnStyleReturnCode.ZFBH_AZBJ_STATUS,getResultMapC(hnMessage,Constants.NumberStr.NUM_STR_TWO));
                }
                hnInterfaceOppositeMapper.updateFlagByKbmrybh(kbmrybh,Constants.NumberStr.NUM_STR_ONE,Constants.HnInterfaceDocking.ZERO_SEVEN_ZERO_TWO_C);
                HnInterfaceOppositeLog hnInterfaceOppositeLog = new HnInterfaceOppositeLog();
                hnInterfaceOppositeLog.setId(com.sinog.biz.util.IdGen.strid());
                hnInterfaceOppositeLog.setPriNum(priNum);
                hnInterfaceOppositeLog.setCreateTime(date1);
                List<PrisonerJxjs> maps = xxblMapper.selectJxjsByPriNum(priNum);
                HashMap<String,Object> resultMap = new HashMap<>(16);
                PrisonerCjpg prisonerCjpg = xxblService.selectCjpgInfoByPrNum(priNum);
                resultMap.put("prisonerCjpg",prisonerCjpg);
                resultMap.put("prisonerJxjs",maps);
                hnInterfaceOppositeLog.setData(JsonUtil.toText(resultMap));
                hnInterfaceOppositeLog.insert();
                // 删除减刑假释,出监评估,衔接信息,安置帮教信息
                Date date = new Date();
                PrisonerMain prisonerMain = prisonerMainMapper.selectPrisonerMain(priNum);
                prisonerMain.setUpdateUser(user.getAccount());
                prisonerMain.setUpdateTime(date);
                prisonerMain.setPriNum(priNum);
                prisonerMain.setStateXj(Constants.NumberStr.NUM_STR_FOUR);
                prisonerMain.setUseridXj(null);
                prisonerMain.setUsernameXj(null);
                prisonerMainMapper.updateById(prisonerMain);
                xxblMapper.deleteJxjsByPriNum(priNum);
                prisonerXjxxMapper.deleteByPriNum(priNum);
                List<XjReceipt> xjReceipts = xjReceiptMapper.selectXjReceiveByPriNum(priNum);
                for(XjReceipt xjReceipt : xjReceipts) {
                    xjReceiptDataVoMapper.deleteBySessionId(xjReceipt.getXjid());
                }
                xjReceiptMapper.deleteByPriNum(priNum);
                // 衔接证据
                UploadAppendixFile uploadAppendixFile = new UploadAppendixFile();
                uploadAppendixFile.setPriNum(priNum);
                uploadAppendixFile.setTaskId(Constants.NumberStr.NUM_STR_TEN);
                uploadAppendixFileMapper.removeAppendixFilByTaskId(uploadAppendixFile);
            }
            // 保存减刑假释
            Result resultJxjs = saveJxjs(Arrays.asList(jxjs),user,hnMessage,date1,priNum);
            // 保存出监评估hnMessage
            Result resultJxjsCjpg = saveCjpg(cjpgFx,cjpg,hnMessage,user,date1,priNum);
            if(!Constants.Number.NUM_ONE.equals(resultJxjs.getCode())) {
                return resultJxjs;
            }
            if(!Constants.Number.NUM_ONE.equals(resultJxjsCjpg.getCode())) {
                return resultJxjsCjpg;
            } else {
                hnInterfaceOpposite.setId(com.sinog.biz.util.IdGen.strid());
                hnInterfaceOpposite.setPriNum(priNum);
                hnInterfaceOpposite.setKbmrybh(kbmrybh);
                hnInterfaceOpposite.setLcslbh(hnMessage.getLcslbh());
                hnInterfaceOpposite.setRwh(hnMessage.getRwh());
                hnInterfaceOpposite.setFsdwCode(hnMessage.getFsdwCode());
                hnInterfaceOpposite.setFsdwName(hnMessage.getFsdwName());
                hnInterfaceOpposite.setFsTime(hnMessage.getFsTime());
                hnInterfaceOpposite.setYsr(hnMessage.getYsr());
                hnInterfaceOpposite.setYsrdh(hnMessage.getYsrdh());
                hnInterfaceOpposite.setCbr(hnMessage.getCbr());
                hnInterfaceOpposite.setCbrdh(hnMessage.getCbrdh());
                hnInterfaceOpposite.setProcessType(hnMessage.getLcjdbh());
                hnInterfaceOpposite.setFileName(hnMessage.getZipName());
                hnInterfaceOpposite.setFlag(Constants.NumberStr.NUM_STR_ZERO);
                hnInterfaceOpposite.setMessageData(JsonUtil.toText(hnMessage));
                hnInterfaceOpposite.setCreateTime(date1);
                hnInterfaceOpposite.setHcType(Constants.NumberStr.NUM_STR_ONE);
                hnInterfaceOpposite.setHzHcZip(Constants.NumberStr.NUM_STR_ONE);
                boolean insertFlage = hnInterfaceOpposite.insert();
                if(!insertFlage) {
                    log.error("入库对接存储记录表失败");
                    throw new RuntimeException("入库对接存储记录表失败");
                }

                //返回结果
                HashMap<String,String> resultMapC = getResultMapC(hnMessage,Constants.NumberStr.NUM_STR_ONE);
                resultMapC.put("PRINUM",priNum);
                return Result.success(resultMapC);
            }
        }
        return Result.failure(HnStyleReturnCode.ZFBH_XXBU_HCSTATE_IS_NOT,getResultMapC(hnMessage,Constants.NumberStr.NUM_STR_TWO));
    }

    /**
     * 发起衔接
     * @param data 发起衔接信息
     * @return Result
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result insertXjxxInface(Map<String,List<Map<String,String>>> data) throws Exception {
        //校验出监评估是否填写
        HnMessageVo hnMessageVo = JsonUtil.toBean(JsonUtil.toText(data.get("MESSAGE").get(0)),HnMessageVo.class);
        String processType = data.get("processType").get(0).get("processType");
        //校验参数
        Result resultCheck = checkUtil.checkParams(data);
        if(!ReturnCode.SUCCESS.code().equals(resultCheck.getCode())) {
            return Result.failure(resultCheck.getCode(),(String)resultCheck.getData(),getResultMapD(hnMessageVo,Constants.NumberStr.NUM_STR_TWO));
        }
        Result result = checkUtil.asscessParams(data,processType);
        Map<String,Object> map = (Map<String,Object>)result.getData();
        PrisonerXixxVo entity = (PrisonerXixxVo)map.get("fqxj");
        hnMessageVo = (HnMessageVo)map.get("hnMessage");
        String kbmrybh = entity.getKbmrybh();
        HnInterfaceOpposite hnInterfaceOpposite = hnInterfaceOppositeMapper.selectHnByKbmrybh(kbmrybh,Constants.HnInterfaceDocking.ZERO_SEVEN_ZERO_TWO_C,Constants.NumberStr.NUM_STR_ZERO);
        if(null != hnInterfaceOpposite) {
            String priNum = hnInterfaceOpposite.getPriNum();
            // 查找服刑信息,未到衔接期无法发起衔接
            PrisonerFx prisonerFx = prisonerFxMapper.getPrisonerFxInfo(priNum);
            if(null != prisonerFx) {
                long l = System.currentTimeMillis();
                String canji = prisonerFx.getCanji();
                Date priStopNow = prisonerFx.getPriStopNow();
                if(null != priStopNow) {
                    // 残疾90+15
                    if(Constants.NumberStr.NUM_STR_ONE.equals(canji) &&
                            Constants.Number.NUM_ONE_ZERO_FIVE < DateUtil.getCalculationDays(priStopNow.getTime(),l)){
                        return Result.failure(HnStyleReturnCode.ZFBH_FQXJ_TIME_IS_LIMITED,getResultMapD(hnMessageVo,Constants.NumberStr.NUM_STR_TWO));
                    } else if (Constants.NumberStr.NUM_STR_TWO.equals(canji)){
                        if(Constants.Number.NUM_FOUR_FIVE < DateUtil.getCalculationDays(priStopNow.getTime(),l)) {
                            return Result.failure(HnStyleReturnCode.ZFBH_FQXJ_TIME_IS_LIMITED,getResultMapD(hnMessageVo,Constants.NumberStr.NUM_STR_TWO));
                        }
                    }
                } else {
                    Date priStop = prisonerFx.getPriStop();
                    if(Constants.NumberStr.NUM_STR_ONE.equals(canji) &&
                            Constants.Number.NUM_ONE_ZERO_FIVE < DateUtil.getCalculationDays(priStop.getTime(),l)){
                        return Result.failure(HnStyleReturnCode.ZFBH_FQXJ_TIME_IS_LIMITED,getResultMapD(hnMessageVo,Constants.NumberStr.NUM_STR_TWO));
                    } else if (Constants.NumberStr.NUM_STR_TWO.equals(canji)){
                        if(Constants.Number.NUM_FOUR_FIVE < DateUtil.getCalculationDays(priStop.getTime(),l)) {
                            return Result.failure(HnStyleReturnCode.ZFBH_FQXJ_TIME_IS_LIMITED,getResultMapD(hnMessageVo,Constants.NumberStr.NUM_STR_TWO));
                        }
                    }
                }
            }
            PrisonerCjpg prisonerCjpg = prisonerFxMapper.selectCjpgInfoByPrNum(priNum);
            if(ObjectUtils.isEmpty(prisonerCjpg)) {
                return Result.failure(HnStyleReturnCode.ZFBH_FQXJ_CJPG_IS_NOT,getResultMapD(hnMessageVo,Constants.NumberStr.NUM_STR_TWO));
            }
            // 获取接口对接用户
            String fsdwCode = hnMessageVo.getFsdwCode();
            UserInterFaceEntity user = userLoginDetailsMapper.getInfoByDepartId(fsdwCode);
            if(null == user) {
                // 找不到用户
                return Result.failure(HnStyleReturnCode.NOT_FIND_USER,getResultMapD(hnMessageVo,Constants.NumberStr.NUM_STR_TWO));
            }
            String departId = user.getDepartid();
            String departName = user.getDepartName();
            String account = user.getAccount();
            // 获取衔接信息
            PrisonerXjxx prisonerXjxx = prisonerXjxxMapper.getXjxxByPriNum(priNum);
            if(null == prisonerXjxx) {
                prisonerXjxx = new PrisonerXjxx();
                prisonerXjxx.setId(IdGen.strid());
            }
            HnInterfaceOpposite hnInterfaceOpposite1 = hnInterfaceOppositeMapper.selectHnByKbmrybh(kbmrybh,Constants.HnInterfaceDocking.ZERO_SEVEN_ZERO_TWO_D,Constants.NumberStr.NUM_STR_ZERO);
            if(null != hnInterfaceOpposite1) {
                // 废除不需要的流程节点(因为hn_interface_opposite表中会有多条对接记录,如果hnInterfaceOpposite1不为空,则需要将之前流程节点的赋予废除标志位)
                //查询该人员是否已经转入安置
                Map<String,Object> abPrisonersResultVo = abPrisonerMapper.getBaseInfoByPriNum(priNum);
                if(MapUtils.isNotEmpty(abPrisonersResultVo)){
                    return Result.failure(HnStyleReturnCode.ZFBH_AZBJ_STATUS,getResultMapD(hnMessageVo,Constants.NumberStr.NUM_STR_TWO));
                }
                hnInterfaceOppositeMapper.updateFlagByKbmrybh(kbmrybh,Constants.NumberStr.NUM_STR_ONE,Constants.HnInterfaceDocking.ZERO_SEVEN_ZERO_TWO_D);
                List<Object> xjReceiptDatas = new ArrayList<>();
                HashMap<String,Object> resultMap = new HashMap<>(16);
                List<XjReceipt> xjReceipts = xjReceiptMapper.selectXjReceiveByPriNum(priNum);
                for(XjReceipt xjReceipt : xjReceipts) {
                    List<XjReceiptDataVo> xjReceiptDataVos = xjReceiptDataVoMapper.selectXjReceiveMessagesBySessionId(xjReceipt.getXjid());
                    xjReceiptDatas.add(xjReceiptDataVos);
                    xjReceiptDataVoMapper.deleteBySessionId(xjReceipt.getXjid());
                }
                resultMap.put("PrisoonerXjxx",prisonerXjxx);
                resultMap.put("xjReceipts",xjReceipts);
                resultMap.put("xjReceiptDatas",xjReceiptDatas);
                xjReceiptMapper.deleteByPriNum(priNum);
                UploadAppendixFile uploadAppendixFile = new UploadAppendixFile();
                uploadAppendixFile.setPriNum(priNum);
                uploadAppendixFile.setTaskId(Constants.NumberStr.NUM_STR_TEN);
                uploadAppendixFileMapper.removeAppendixFilByTaskId(uploadAppendixFile);
                HnInterfaceOppositeLog hnInterfaceOppositeLog = new HnInterfaceOppositeLog();
                hnInterfaceOppositeLog.setId(com.sinog.biz.util.IdGen.strid());
                hnInterfaceOppositeLog.setPriNum(priNum);
                Date date1 = new Date();
                hnInterfaceOppositeLog.setCreateTime(date1);
                hnInterfaceOppositeLog.setData(JsonUtil.toText(resultMap));
                hnInterfaceOppositeLog.insert();
            }
            //修改主表衔接状态
            try {
                Date date = new Date();
                PrisonerMain prisonerMain = prisonerMainMapper.selectPrisonerMain(priNum);
                // 衔接状态信息
                String xjcs = data.get("FQXJ").get(0).get("XJCS");
                if(Constants.NumberStr.NUM_STR_ONE.equals(xjcs)) {
                    prisonerMain = new PrisonerMain();
                    prisonerMain.setUpdateUser(user.getAccount());
                    prisonerMain.setUpdateTime(date);
                    prisonerMain.setId(entity.getId());
                    prisonerMain.setPriNum(priNum);
                    prisonerMain.setStateXj(Constants.NumberStr.NUM_STR_TWO);
                    prisonerMain.setUseridXj(departId);
                    prisonerMain.setUsernameXj(departName);
                    prisonerMainMapper.updateById(prisonerMain);
                    prisonerXjxx.setSecondProvince(null);
                    prisonerXjxx.setSecondCity(null);
                    prisonerXjxx.setSecondCounty(null);
                    prisonerXjxx.setSecondStreet(null);
                    prisonerXjxx.setSecondState(null);
                    prisonerXjxx.setSecondStateXj(null);
                    // 再次发起衔接
                } else if(Constants.NumberStr.NUM_STR_TWO.equals(xjcs)) {
                    String hjdxxdz = data.get("FQXJ").get(0).get("HJDXXDZ");
                    // 第一步,根据priNum,判断是否是否为衔接失败状态,如果是则执行
                    String stateXj = prisonerMain.getStateXj();
                    if(Constants.NumberStr.NUM_STR_THREE.equals(stateXj)) {
                        prisonerMain.setUpdateUser(user.getAccount());
                        prisonerMain.setUpdateTime(date);
                        prisonerMain.setStateXj(Constants.NumberStr.NUM_STR_THREE);
                        prisonerMain.setUseridXj(departId);
                        prisonerMain.setUsernameXj(departName);
                        prisonerMainMapper.updateById(prisonerMain);
                        prisonerXjxx.setUpdateUser(user.getAccount());
                        prisonerXjxx.setUpdateTime(date);
                        prisonerXjxx.setSecondState(Constants.NumberStr.NUM_STR_THREE);
                        prisonerXjxx.setSecondStateXj(Constants.NumberStr.NUM_STR_ZERO);
                        String address = getAddress(hjdxxdz);
                        Map<String,Object> allArea = dataTransmissionService.getVagueAllArea(address);
                        String sheng;
                        String shi;
                        String xian;
                        String jiedao;
                        if(allArea.size() > 0) {
                            sheng = allArea.get("sheng_code").toString();
                            shi = allArea.get("dishi_code").toString();
                            xian = allArea.get("quxian_code").toString();
                            jiedao = allArea.get("jiedao_code").toString();
                            prisonerXjxx.setSecondProvince(sheng);
                            prisonerXjxx.setSecondCity(shi);
                            prisonerXjxx.setSecondCounty(xian);
                            prisonerXjxx.setSecondStreet(jiedao);
                        } else {
                            return Result.failure(HnStyleReturnCode.PRISONERMAIN_HJDXXDZ_IS_ERROR,getResultMapD(hnMessageVo,Constants.NumberStr.NUM_STR_TWO));
                        }
                    }
                }
                String sfsId = prisonerMain.getNativevill();
                String sfsName = prisonerMain.getNativevillName();
                //对衔接类别和衔接方式做判断
                String pinggu = prisonerFx.getPinggu();
                String aftype = prisonerFx.getAftype();
                String wushe = prisonerFx.getWushe();
                String shehei = prisonerFx.getShehei();
                String shekong = prisonerFx.getShekong();
                String weifa = prisonerFx.getWeifa();
                String sanwu = prisonerFx.getSanwu();
                //系统自己做判断
                prisonerXjxx.setType(pinggu);
                //条件
                //监狱送回条件(一般帮教和重点帮教)
                boolean booleanOne = Constants.NumberStr.NUM_STR_ONE.equals(wushe) && (Constants.StrFinalValue.TRUEVALUE.equals(shehei) || Constants.StrFinalValue.TRUEVALUE.equals(shekong));
                //监狱送回条件(重点帮教)
                boolean booleanTwo = Constants.NumberStr.NUM_STR_ONE.equals(aftype) && Constants.NumberStr.NUM_STR_ONE.equals(weifa);

                if(Constants.NumberStr.NUM_STR_ZERO_ONE.equals(pinggu)){
                   //重点帮教方式
                    if(booleanOne || booleanTwo){
                        prisonerXjxx.setZhongdian(Constants.NumberStr.NUM_STR_ZERO_ONE);
                    }else if(Constants.NumberStr.NUM_STR_ONE.equals(sanwu)){
                        prisonerXjxx.setZhongdian(Constants.NumberStr.NUM_STR_ZERO_TWO);
                    }else{
                        if(null==entity.getZhongdian()){
                            return Result.failure(HnStyleReturnCode.PRISONERXJXX_ZDXJDX_IS_NULL,getResultMapD(hnMessageVo,Constants.NumberStr.NUM_STR_TWO));
                        }else if(Constants.NumberStr.NUM_STR_ZERO_FIVE.equals(entity.getYiban()) || Constants.NumberStr.NUM_STR_ZERO_SIX.equals(entity.getYiban())){
                            prisonerXjxx.setZhongdian(entity.getYiban());
                        }else{
                            return Result.failure(HnStyleReturnCode.PRISONERXJXX_YBXJDX_IS_RRROR,getResultMapD(hnMessageVo,Constants.NumberStr.NUM_STR_TWO));
                        }
                    }

                    prisonerXjxx.setZhongdian(entity.getZhongdian());
                }else if(Constants.NumberStr.NUM_STR_ZERO_TWO.equals(pinggu)){
                   //一般帮教方式
                    if(booleanOne){
                        prisonerXjxx.setYiban(Constants.NumberStr.NUM_STR_ZERO_ONE);
                    }else{
                        if(null==entity.getYiban()){
                            return Result.failure(HnStyleReturnCode.PRISONERXJXX_YBXJDX_IS_NULL,getResultMapD(hnMessageVo,Constants.NumberStr.NUM_STR_TWO));
                        }else if(Constants.NumberStr.NUM_STR_ZERO_THREE.equals(entity.getYiban()) || Constants.NumberStr.NUM_STR_ZERO_FOUR.equals(entity.getYiban())){
                            prisonerXjxx.setYiban(entity.getYiban());
                        }else{
                            return Result.failure(HnStyleReturnCode.PRISONERXJXX_YBXJDX_IS_RRROR,getResultMapD(hnMessageVo,Constants.NumberStr.NUM_STR_TWO));
                        }
                    }
                }
                //衔接表
                prisonerXjxx.setCreateUser(user.getAccount());
                prisonerXjxx.setCreateTime(date);
                prisonerXjxx.setUpdateUser(user.getAccount());
                prisonerXjxx.setUpdateTime(date);
                prisonerXjxx.setPriNum(hnInterfaceOpposite.getPriNum());
                prisonerXjxx.setTujing(entity.getTujing());
                prisonerXjxx.setLianxiren(entity.getLianxiren());
                prisonerXjxx.setDianhua(entity.getDianhua());
                prisonerXjxx.setJhsj(entity.getJhsj());
                prisonerXjxx.setJhdd(entity.getJhdd());
                prisonerXjxx.setCreateTime(date);
                prisonerXjxx.setAdduserid(departId);
                prisonerXjxx.setAddusername(departName);
                prisonerXjxx.setCreateUser(user.getAccount());
                prisonerXjxx.setCreateTime(date);
                prisonerXjxx.setUpdateUser(user.getAccount());
                prisonerXjxx.setUpdateTime(date);
                prisonerXjxxService.saveOrUpdate(prisonerXjxx);
                //衔接的同时生成一条回执中间表数据
                XjReceipt xjReceipt = new XjReceipt();
                xjReceipt.setXjid(com.sinog.biz.util.IdGen.strid());
                xjReceipt.setPriNum(prisonerXjxx.getPriNum());
                xjReceipt.setSendCode(prisonerXjxx.getAdduserid());
                xjReceipt.setSendName(prisonerXjxx.getAddusername());
                xjReceipt.setReceiveCode(null == sfsId ? "" : sfsId);
                xjReceipt.setReceiveName(null == sfsName ? "" : sfsName);
                xjReceipt.setCreateUser(account);
                xjReceipt.setCreateTime(date);
                xjReceipt.setUpdateTime(date);
                xjReceipt.setUpdateUser(account);
                xjReceipt.setSessionFlag(Constants.NumberStr.NUM_STR_ZERO);
                xjReceipt.setFlag(Constants.NumberStr.NUM_STR_TWO);
                xjReceiptMapper.saveXjReceive(xjReceipt);
                //保存信息表
                String xjid = xjReceipt.getXjid();
                XjReceiptData xjReceiptData = new XjReceiptData();
                xjReceiptData.setSessionId(xjid);
                xjReceiptData.setLiaisonMan(entity.getLianxiren());
                xjReceiptData.setLiaisonPhone(entity.getDianhua());
                xjReceiptData.setTakebackTime(entity.getJhsj());
                xjReceiptData.setTakebackAddress(entity.getJhdd());
                xjReceiptData.setCreateUser(account);
                xjReceiptData.setOwnerFlag(Constants.NumberStr.NUM_STR_ONE);
                xjReceiptData.setCreateTime(date);
                xjReceiptData.setUpdateUser(account);
                xjReceiptData.setUpdateTime(date);
                xjReceiptDataVoMapper.saveXjReceiveMessage(xjReceiptData);
                //日志记录
                hnInterfaceOpposite.setId(com.sinog.biz.util.IdGen.strid());
                hnInterfaceOpposite.setCreateTime(date);
                hnInterfaceOpposite.setKbmrybh(kbmrybh);
                hnInterfaceOpposite.setLcslbh(hnMessageVo.getLcslbh());
                hnInterfaceOpposite.setRwh(hnMessageVo.getRwh());
                hnInterfaceOpposite.setFsdwCode(hnMessageVo.getFsdwCode());
                hnInterfaceOpposite.setFsdwName(hnMessageVo.getFsdwName());
                hnInterfaceOpposite.setFsTime(hnMessageVo.getFsTime());
                hnInterfaceOpposite.setYsr(hnMessageVo.getYsr());
                hnInterfaceOpposite.setYsrdh(hnMessageVo.getYsrdh());
                hnInterfaceOpposite.setCbr(hnMessageVo.getCbr());
                hnInterfaceOpposite.setCbrdh(hnMessageVo.getCbrdh());
                hnInterfaceOpposite.setProcessType(hnMessageVo.getLcjdbh());
                hnInterfaceOpposite.setPriNum(prisonerMain.getPriNum());
                hnInterfaceOpposite.setMessageData(JsonUtil.toText(hnMessageVo));
                hnInterfaceOpposite.setPgType(Constants.NumberStr.NUM_STR_ONE);
                hnInterfaceOpposite.setHcType(Constants.NumberStr.NUM_STR_ONE);
                hnInterfaceOpposite.setHzHcZip(Constants.NumberStr.NUM_STR_ONE);
                if(!hnInterfaceOpposite.insert()) {
                    log.error("入库对接存储记录表失败");
                    throw new RuntimeException("入库对接存储记录表失败");
                }
            } catch(RuntimeException e) {
                e.printStackTrace();
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
            HashMap<String,String> resultMap = getResultMapD(hnMessageVo,Constants.NumberStr.NUM_STR_ONE);
            resultMap.put("PRINUM",priNum);
            return Result.success(resultMap);
        }
        return Result.failure(HnStyleReturnCode.ZFBH_XXBU_HCSTATE_IS_NOT,getResultMapD(hnMessageVo,Constants.NumberStr.NUM_STR_TWO));
    }
    /**
     * 插入减刑假释
     * @param jxjss 减刑假释信息
     * @param user 用户信息
     * @return Result
     */
    @Transactional(rollbackFor = Exception.class)
    public Result saveJxjs(List<PrisonerJxjs> jxjss,UserInterFaceEntity user,HnMessageVo hnMessage,Date date,String priNum) throws ParseException {
        for(PrisonerJxjs jxjs : jxjss) {
            jxjs.setPriNum(priNum);
            //根据id选择fx数据对象
            PrisonerFx p = prisonerFxMapper.selectById(priNum);
            if(ObjectUtils.isEmpty(p)) {
                return Result.failure(HnStyleReturnCode.ZFBH_IS_NOT,getResultMapC(hnMessage,Constants.NumberStr.NUM_STR_TWO));
            }
            p.setUpdateUser(user.getAccount());
            p.setUpdateTime(date);
            //减刑假释表的id
            String id = IdGen.strid();
            //用户名
            String createUser = user.getUsername();
            //上一次的刑期止日
            String priStopOld = jxjs.getPriStopOld();
            //现刑期类型
            String subRange = jxjs.getSubRange();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String priStopTemp = jxjs.getPriStop();
            Date priStop = null;
            if(Constants.PritimeTypeNow.PRITIME_YOUQI.equals(subRange) || Constants.PritimeTypeNow.PRITIME_GUANZHI.equals(subRange) || Constants.PritimeTypeNow.PRITIME_JUYI.equals(subRange)) {
                if(StringUtils.isNotEmpty(priStopTemp)) {
                    priStop = simpleDateFormat.parse(priStopTemp);
                    Date priBegin = p.getPriBegin();
                    if(ObjectUtils.allNotNull(priStop) && priBegin.after(priStop)) {
                        return Result.failure(5000,"刑期止日不能小于刑期起日",getResultMapC(hnMessage,Constants.NumberStr.NUM_STR_TWO));
                    }
                } else {
                    return Result.failure(HnStyleReturnCode.PRISONERSJXJS_XXQZR_IS_NULL,getResultMapC(hnMessage,Constants.NumberStr.NUM_STR_TWO));
                }
                //将刑期止日set进fx表里
                p.setPriStop(priStop);
            } else {
                if(StringUtils.isNotBlank(priStopTemp)) {
                    return Result.failure(HnStyleReturnCode.PRISONERSJXJS_XXQZR_IS_ERROR,getResultMapC(hnMessage,Constants.NumberStr.NUM_STR_TWO));
                }
            }
            //现在用的是jxjs表里的pri_stop_old字段用来放置上一次的刑期止日
            p.setRemark(priStopOld);
            //将现刑期类型更新进fx表
            p.setPritime(subRange);
            //保存减刑假释数据
            if(Constants.Number.NUM_ZERO < xxblMapper.saveJxjsInfo(id,subRange,priStop,priNum,createUser,priStopOld,date)) {
                int resultHn = prisonerFxMapper.updatePriStopHn(priNum,priStopOld);
                int result = prisonerFxMapper.updatePriStopAndPritime(priNum,priStop,priStopOld,subRange,user.getAccount(),date);
                if(Constants.Number.NUM_ZERO > result || Constants.Number.NUM_ZERO > resultHn) {
                    return Result.failure(ReturnCode.SAVE_FAILED,getResultMapC(hnMessage,Constants.NumberStr.NUM_STR_TWO));
                }
            } else {
                return Result.failure(ReturnCode.SAVE_FAILED,getResultMapC(hnMessage,Constants.NumberStr.NUM_STR_TWO));
            }
        }
        return Result.success("保存减刑假释信息成功！");
    }

    /**
     * 插入出监评估信息
     * @param prisonerFx 服刑信息
     * @param cjpg 出监信息
     * @param hnMessage hnMessage
     * @return Result
     */
    @Transactional(rollbackFor = Exception.class)
    public Result saveCjpg(PrisonerFx prisonerFx,PrisonerCjpg cjpg,HnMessageVo hnMessage,UserInterFaceEntity user,Date date,String priNum) {
        Result cjpgResult;
        prisonerFx.setUpdateUser(user.getAccount());
        prisonerFx.setUpdateTime(date);
        prisonerFx.setPriNum(priNum);
        //危险评估自动判定
        String sanwu = prisonerFx.getSanwu();
        String sanjia = prisonerFx.getSanjia();
        String weifa = prisonerFx.getWeifa();
        String addpenalty = prisonerFx.getAftype();
        if(StringUtils.equalsAny(Constants.NumberStr.NUM_STR_ONE,sanwu,sanjia,weifa,addpenalty)){
            prisonerFx.setPinggu(Constants.NumberStr.NUM_STR_ZERO_ONE);
        }else{
            prisonerFx.setPinggu(Constants.NumberStr.NUM_STR_ZERO_TWO);
        }
        //保存出监评估
        PrisonerCjpg prisonerCjpg = xxblService.selectCjpgInfoByPrNum(priNum);
        if(prisonerFx.getWushe().equals(Constants.NumberStr.NUM_STR_ONE)) {
            if(StringUtils.isBlank(prisonerFx.getShekong()) && StringUtils.isBlank(prisonerFx.getShexie()) && StringUtils.isBlank(prisonerFx.getShedu()) && StringUtils.isBlank(prisonerFx.getShehei()) && StringUtils.isBlank(prisonerFx.getSheqiang())) {
                return Result.failure(HnStyleReturnCode.PRISONERCJPG_SFWS_IS_ERROR,getResultMapD(hnMessage,Constants.NumberStr.NUM_STR_TWO));
            }
        }
        if(prisonerFx.getSishi().equals(Constants.NumberStr.NUM_STR_ONE)) {
            if(StringUtils.isBlank(prisonerFx.getXijing()) && StringUtils.isBlank(prisonerFx.getTaotuo()) && StringUtils.isBlank(prisonerFx.getZisha()) && StringUtils.isBlank(prisonerFx.getDrughis())) {
                return Result.failure(HnStyleReturnCode.PRISONERCJPG_SFSS_IS_ERROR,getResultMapD(hnMessage,Constants.NumberStr.NUM_STR_TWO));
            }
        }
        if(prisonerFx.getSanwu().equals(Constants.NumberStr.NUM_STR_ONE)) {
            if(StringUtils.isBlank(prisonerFx.getWujia()) && StringUtils.isBlank(prisonerFx.getWuqin()) && StringUtils.isBlank(prisonerFx.getWuye())) {
                return Result.failure(HnStyleReturnCode.PRISONERCJPG_SFSWRY_IS_ERROR,getResultMapD(hnMessage,Constants.NumberStr.NUM_STR_TWO));
            }
        }
        if(prisonerFx.getSanjia().equals(Constants.NumberStr.NUM_STR_ONE)) {
            if(StringUtils.isBlank(prisonerFx.getJxm()) && StringUtils.isBlank(prisonerFx.getJsf()) && StringUtils.isBlank(prisonerFx.getJhj())) {
                return Result.failure(HnStyleReturnCode.PRISONERCJPG_SFSJ_IS_ERROR,getResultMapD(hnMessage,Constants.NumberStr.NUM_STR_TWO));
            }
        }
        if(null != prisonerCjpg) {
            prisonerCjpg.setUpdateUser(user.getAccount());
            prisonerCjpg.setUpdateTime(date);
            Map<String,Object> jsonMap = MapUtil.entityToMap(prisonerCjpg);
            int cjpgState = prisonerFxMapper.updateCjpgInfoByPrNum(jsonMap);
            Map<String,Object> resultMap = new HashMap<>(16);
            resultMap.put("id",jsonMap.get("id"));
            if(Constants.Number.NUM_ZERO < cjpgState) {
                cjpgResult = Result.success(resultMap);
            } else {
                cjpgResult = Result.failure(ReturnCode.FAILURE,getResultMapD(hnMessage,Constants.NumberStr.NUM_STR_TWO));
            }
        } else { //新增
            cjpg.setCreateUser(user.getAccount());
            cjpg.setCreateTime(date);
            cjpg.setUpdateUser(user.getAccount());
            cjpg.setUpdateTime(date);
            String id = IdGen.strid();
            cjpg.setPriNum(priNum);
            cjpg.setId(id);
            boolean insert = cjpg.insert();
            Map<String,Object> resultMap = new HashMap<>(16);
            resultMap.put("id",id);
            if(insert) {
                cjpgResult = Result.success(resultMap);
            } else {
                cjpgResult = Result.failure(ReturnCode.SAVE_FAILED,getResultMapD(hnMessage,Constants.NumberStr.NUM_STR_TWO));
            }
        }
        if(Constants.Number.NUM_ONE.equals(cjpgResult.getCode())) {
            if(StringUtils.isBlank(cjpg.getXd())) {
                cjpg.setXd(Constants.NumberStr.NUM_STR_TWO);
            }
            String xd = cjpg.getXd();
            Map<String,Object> map = new HashMap<>(16);
            map.put("priNum",priNum);
            map.put("xd",xd);
            int cpState = prisonerFxMapper.updateCjpgInfoByPrNum(map);
            //危险性评估信息更新
            int pfState = prisonerFxMapper.update(prisonerFx,new UpdateWrapper<PrisonerFx>().eq("pri_num",prisonerFx.getPriNum()));
            if(Constants.Number.NUM_ZERO < pfState && cpState == pfState) {
                return Result.success("出监评估信息保存成功！");
            }
            return Result.failure(ReturnCode.SAVE_FAILED,getResultMapD(hnMessage,Constants.NumberStr.NUM_STR_TWO));
        } else {
            return Result.failure(ReturnCode.SAVE_FAILED,getResultMapD(hnMessage,Constants.NumberStr.NUM_STR_TWO));
        }
    }

    /**
     * 返回XML信息,跨部门办案号,流程实例编号
     * @param hnMessage hnMessage
     * @param type 1:接收成功,2:接收失败
     * @return Object
     */
    private <T extends Object> T getResultMapC(HnMessageVo hnMessage,String type) {
        HashMap<String,String> resultMap = new HashMap<>(16);
        resultMap.put("KBMBAH",null == hnMessage.getKbmbah() ? "" : hnMessage.getKbmbah());
        resultMap.put("RWH",null == hnMessage.getRwh() ? "" : hnMessage.getRwh());
        resultMap.put("LCSLBH",null == hnMessage.getLcslbh() ? "" : hnMessage.getLcslbh());
        resultMap.put("PROCESS_NO",Constants.HnInterfaceDocking.ZERO_SEVEN_ZERO_TWO_C);
        resultMap.put("AJMC",null == hnMessage.getAjmc() ? "" : hnMessage.getAjmc());
        resultMap.put("LCLX_CODE",Constants.HnInterfaceDocking.ZERO_SEVEN_ZERO_TWO);
        resultMap.put("LCLX_NAME",Constants.HnInterfaceDocking.ZHIXINGJIESHOU);
        resultMap.put("JSDWLX","4B");
        Map<String,Map<String,String>> tsmessage = provinceCodes3Config.getTSMESSAGE();
        Map<String,String> fsdwCodes = tsmessage.get("FSDW_CODE");
        for(Map.Entry<String,String> fsdw : fsdwCodes.entrySet()) {
            if(fsdw.getKey().indexOf(hnMessage.getFsdwCode())>=0 || fsdw.getValue().indexOf(hnMessage.getFsdwCode())>=0 ){
                resultMap.put("JSDW_CODE",fsdw.getKey());
            }
        }
        resultMap.put("JSDW_NAME",null == hnMessage.getFsdwName() ? "" : hnMessage.getFsdwName());
        resultMap.put("JSDWSZD",null == hnMessage.getFsdwszd() ? "" : hnMessage.getFsdwszd());
        resultMap.put("JSDWXZQ_CODE",null == hnMessage.getJsdwxzqCode() ? "" : hnMessage.getJsdwxzqCode());
        resultMap.put("JSDWXZQ_NAME",null == hnMessage.getJsdwxzqName() ? "" : hnMessage.getJsdwxzqName());
        resultMap.put("FSDWLX","5D");
        resultMap.put("FSDW_CODE",null == hnMessage.getJsdwCode() ? "" : hnMessage.getJsdwCode());
        resultMap.put("FSDW_NAME",null == hnMessage.getJsdwName() ? "" : hnMessage.getJsdwName());
        resultMap.put("FSDWSZD",null == hnMessage.getJsdwszd() ? "" : hnMessage.getJsdwszd());
        resultMap.put("FSDWXZQ_CODE",null == hnMessage.getFsdwxzqCode() ? "" : hnMessage.getFsdwxzqCode());
        resultMap.put("FSDWXZQ_NAME",null == hnMessage.getFsdwxzqName()? "" : hnMessage.getFsdwxzqName());
        resultMap.put("FS_TIME",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        resultMap.put("JGZT",Constants.NumberStr.NUM_STR_ONE.equals(type) ? Constants.HnInterfaceDocking.NUM_STR_TWO_ZERO_TWO : Constants.HnInterfaceDocking.NUM_STR_FOUR_ZERO_TWO);
        resultMap.put("ZTMS",Constants.NumberStr.NUM_STR_ONE.equals(type) ? "接收成功" : "接收失败");
        resultMap.put("YSR","");
        resultMap.put("YSRDH","");
        resultMap.put("CBR","");
        resultMap.put("CBRDH","");
        resultMap.put("ZIPNAME",null == hnMessage.getZipName() ? "" : hnMessage.getZipName());
        return (T)resultMap;
    }

    /**
     * 返回XML信息,跨部门办案号,流程实例编号
     * @param hnMessage hnMessage
     * @param type 1:接收成功,2:接收失败
     * @return Object
     */
    private <T extends Object> T getResultMapD(HnMessageVo hnMessage,String type) {
        HashMap<String,String> resultMap = new HashMap<>(16);
        resultMap.put("KBMBAH",null == hnMessage.getKbmbah() ? "" : hnMessage.getKbmbah());
        resultMap.put("RWH",null == hnMessage.getRwh() ? "" : hnMessage.getRwh());
        resultMap.put("LCSLBH",null == hnMessage.getLcslbh() ? "" : hnMessage.getLcslbh());
        resultMap.put("PROCESS_NO",Constants.HnInterfaceDocking.ZERO_SEVEN_ZERO_TWO_D);
        resultMap.put("AJMC",null == hnMessage.getAjmc() ? "" : hnMessage.getAjmc());
        resultMap.put("LCLX_CODE",Constants.HnInterfaceDocking.ZERO_SEVEN_ZERO_TWO);
        resultMap.put("LCLX_NAME",Constants.HnInterfaceDocking.ZHIXINGJIESHOU);
        resultMap.put("JSDWLX","4B");
        Map<String,Map<String,String>> tsmessage = provinceCodes3Config.getTSMESSAGE();
        Map<String,String> fsdwCodes = tsmessage.get("FSDW_CODE");
        for(Map.Entry<String,String> fsdw : fsdwCodes.entrySet()) {
            if(fsdw.getKey().indexOf(hnMessage.getFsdwCode())>=0 || fsdw.getValue().indexOf(hnMessage.getFsdwCode())>=0 ){
                resultMap.put("JSDW_CODE",fsdw.getKey());
            }
        }
        resultMap.put("JSDW_NAME",null == hnMessage.getFsdwName() ? "" : hnMessage.getFsdwName());
        resultMap.put("JSDWSZD",null == hnMessage.getFsdwszd() ? "" : hnMessage.getFsdwszd());
        resultMap.put("JSDWXZQ_CODE",null == hnMessage.getJsdwxzqCode() ? "" : hnMessage.getJsdwxzqCode());
        resultMap.put("JSDWXZQ_NAME",null == hnMessage.getJsdwxzqName() ? "" : hnMessage.getJsdwxzqName());
        resultMap.put("FSDWLX","5D");
        resultMap.put("FSDW_CODE",null == hnMessage.getJsdwCode() ? "" : hnMessage.getJsdwCode());
        resultMap.put("FSDW_NAME",null == hnMessage.getJsdwName() ? "" : hnMessage.getJsdwName());
        resultMap.put("FSDWSZD",null == hnMessage.getJsdwszd() ? "" : hnMessage.getJsdwszd());
        resultMap.put("FSDWXZQ_CODE",null == hnMessage.getFsdwxzqCode() ? "" : hnMessage.getFsdwxzqCode());
        resultMap.put("FSDWXZQ_NAME",null == hnMessage.getFsdwxzqName() ? "" : hnMessage.getFsdwxzqName());
        resultMap.put("FS_TIME",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        resultMap.put("JGZT",Constants.NumberStr.NUM_STR_ONE.equals(type) ? Constants.HnInterfaceDocking.NUM_STR_TWO_ZERO_TWO : Constants.HnInterfaceDocking.NUM_STR_FOUR_ZERO_TWO);
        resultMap.put("ZTMS",Constants.NumberStr.NUM_STR_ONE.equals(type) ? "接收成功" : "接收失败");
        resultMap.put("YSR","");
        resultMap.put("YSRDH","");
        resultMap.put("CBR","");
        resultMap.put("CBRDH","");
        resultMap.put("ZIPNAME",null == hnMessage.getZipName() ? "" : hnMessage.getZipName());
        return (T)resultMap;
    }

    /**
     * 获取住址信息
     * @param address 住址
     * @return String
     */
    private String getAddress(String address) {
        String[] str1 = address.split("街道");
        String[] str2 = str1[0].split("镇");
        String[] str3 = str2[0].split("乡");
        String[] str4 = str3[0].split("民族乡");
        String[] str5 = str4[0].split("苏木");
        String[] str6 = str5[0].split("民族苏木");
        String[] str7 = str6[0].split("市辖区");
        return str7[0];
    }
}